<template>
	<view>
		<view class="list">
			<view class="addStore" @tap="goSign()">注册商户</view>

			<view class="list-item" v-for="(item, index) in list" :key="index">
				<view class="list-title">{{ item.storeName }}</view>
				<view class="list-infos">地址：{{ item.address }}</view>
				<view class="list-infos">联系电话：{{ item.telephone }}</view>
				<view class="list-right" @tap="changeIsShow(item.storeId,item.examine)">···</view>
				<view class="list-del" v-if="item.storeId === num" @tap="del(item.storeId)">注销</view>
				<view class="list-state" v-if="item.examine == 0">审核中</view>
				<view class="list-state" v-if="item.examine == 2">审核失败</view>
				<view class="list-state" v-if="item.examine == 3">已注销</view>
			</view>
		</view>
	</view>
</template>

<script>
import config from '@/common/config.js';
export default {
	data() {
		return {
			apiUrl: config.apiHost,
			imgUrl: config.ImageUrl,
			list: [],
			userId: uni.getStorageSync('userId'),
			num: -1
		};
	},
	onLoad(option) {
		console.log(option)
		this.getList();
	},
	methods: {
		changeIsShow(index,examine) {
			if(examine != 1){
				return
			}
			if (index == this.num) {
				this.num = -1;
			} else {
				this.num = index;
			}
		},
		getList() {
			uni.request({
				url: this.apiUrl + '/api/store/selectStoreBySuperId',
				method: 'GET',
				contentType: 'application/jason',
				data: {
					userId: this.userId
				},
				success: res => {
					if (res.data.code == 200) {
						this.list = res.data.data;
					} else {
						uni.showToast({
							icon: 'none',
							title: '请求失败'
						});
					}
				}
			});
		},
		del(storeId) {
			let self = this
			uni.showModal({
				title: '提示',
				content: '是否确认注销该门店',
				success: function(res) {
					self.num = -1
					console.log(self.apiUrl)
					if (res.confirm) {
						uni.request({
						    url: self.apiUrl + '/api/store/updateStoreStateByStoreId',
						    method:"POST",
							contentType: 'application/jason',
							data:{
								storeId: storeId,
								state: 3
							},
						    success: (res) => {
								self.getList();
								if(res.data.code==200){
									uni.showToast({
										icon:'none',
										title:'操作成功'
									})
								}
						    }
						});
					}
				}
			});
		},
		goSign(){
			uni.navigateTo({
				url:'../becomeStore/becomeStore'
			})
		}
	}
};
</script>

<style>
.list {
	background-color: #fff;
}

.addStore {
	width: 100%;
	height: 50upx;
	line-height: 50upx;
	text-align: center;
	border-top: 1upx solid #f5f5f5;
}
.list-item {
	border-top: 1upx solid #f5f5f5;
	padding: 28upx 24upx;
	height: 200upx;
	position: relative;
}
.list-title {
	width: 100%;
	height: 44upx;
	line-height: 44upx;
	font-size: 32upx;
	font-family: PingFangSC-Semibold, PingFang SC;
	font-weight: 600;
	color: rgba(34, 34, 34, 1);
}
.list-infos {
	height: 40upx;
	margin-top: 12upx;
	font-size: 28upx;
	font-family: PingFangSC;
	color: rgba(102, 101, 101, 1);
	line-height: 40upx;
}
.list-right {
	position: absolute;
	right: 28upx;
	top: 20upx;
}
.list-state {
	position: absolute;
	right: 28upx;
	bottom: 28upx;
	font-size: 28upx;
	font-family: PingFangSC;
	color: rgba(245, 4, 4, 1);
}

.list-del {
	width: 92upx;
	height: 48upx;
	text-align: center;
	line-height: 48upx;
	color: #fff;
	background-color: #f50505;
	position: absolute;
	right: 26upx;
	top: 67upx;
	border-radius: 5upx;
}
</style>
